<template>
  <div class="video-container">
    <div class="header">
      <h2>监控视频上传</h2>
      <el-button type="primary" @click="handleUpload">上传视频</el-button>
    </div>

    <el-table :data="videoList" border style="width: 100%">
      <el-table-column prop="name" label="视频名称" width="200"/>
      <el-table-column prop="uploadTime" label="上传时间" width="180"/>
      <el-table-column prop="location" label="监控位置"/>
      <el-table-column prop="status" label="处理状态" width="120"/>
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-button size="small" @click="handleView(scope.row)">查看</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 上传视频对话框 -->
    <el-dialog
      title="上传监控视频"
      v-model="dialogVisible"
      width="50%">
      <el-form :model="form" label-width="100px">
        <el-form-item label="视频名称">
          <el-input v-model="form.name"/>
        </el-form-item>
        <el-form-item label="监控位置">
          <el-input v-model="form.location"/>
        </el-form-item>
        <el-form-item label="视频文件">
          <el-upload
            class="upload-demo"
            action="#"
            :auto-upload="false">
            <el-button type="primary">选择文件</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="handleSubmit">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive,onMounted } from 'vue'

const videoList = ref([])
const dialogVisible = ref(false)

const form = reactive({
  name: '',
  location: '',
  file: null
})
// 生成随机视频数据的函数
const generateRandomVideoData = () => {
  const names = ['监控视频1', '监控视频2', '监控视频3', '监控视频4', '监控视频5']
  const locations = ['地点A', '地点B', '地点C', '地点D', '地点E']
  const statuses = ['待处理', '处理中', '已完成']

  return Array.from({ length: 5 }, () => ({
    name: names[Math.floor(Math.random() * names.length)],
    uploadTime: new Date(Date.now() - Math.floor(Math.random() * 10000000000)).toLocaleString(), // 随机上传时间
    location: locations[Math.floor(Math.random() * locations.length)],
    status: statuses[Math.floor(Math.random() * statuses.length)],
  }))
}

// 在组件加载时生成随机视频数据
onMounted(() => {
  videoList.value = generateRandomVideoData()
})

const handleUpload = () => {
  dialogVisible.value = true
}

const handleView = (row: any) => {
  // TODO: 实现视频查看逻辑
}

const handleDelete = (row: any) => {
  // TODO: 实现删除逻辑
}

const handleSubmit = () => {
  // TODO: 实现提交逻辑
  dialogVisible.value = false
}
</script>

<style scoped>
.video-container {
  padding: 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header h2 {
  margin: 0;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style>
